package com.dog.basics.admin.controller.common;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.dog.basics.bean.dto.admin.common.PositioninfoAddDto;
import com.dog.basics.bean.dto.admin.common.PositioninfoEditDto;
import com.dog.basics.bean.dto.admin.common.PositioninfoFormDto;
import com.dog.basics.bean.vo.admin.common.PositioninfoVo;
import com.dog.basics.bean.vo.api.common.AllPositioninfoVo;
import com.dog.basics.common.annotation.SysLog;
import com.dog.basics.common.constant.SwaggerConstants;
import com.dog.basics.common.util.PageParam;
import com.dog.basics.common.util.R;
import com.dog.basics.service.common.IDogComPositioninfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 省市区信息 前端控制器
 * </p>
 *
 * @author zmr
 * @since 2020-05-27
 */
@RestController
@RequestMapping("/admin/positioninfo")
@Api(value = SwaggerConstants.COMMON + "省市区信息模块", tags = SwaggerConstants.COMMON + "省市区信息模块")
@AllArgsConstructor
public class DogComPositioninfoController {
    private final IDogComPositioninfoService iDogComPositioninfoService;

    /**
     * @Description: 增加省市区信息
     * @Param: PositioninfoAddDto
     * @return: Boolean
     * @Author: zhangrm
     * @Date: 2020/05/27 0027
     */
    @SysLog("增加省市区信息")
    @ApiOperation(value = "增加省市区信息", notes = "pc:positioninfo:save")
    @PostMapping("/save")
    @PreAuthorize("@pms.hasPermission('pc:positioninfo:save')")
    public R<Boolean> save(@Valid @RequestBody PositioninfoAddDto obj) {
        return R.ok(iDogComPositioninfoService.saveObj(obj));
    }

    /**
     * @Description: 删除省市区信息
     * @Param: id
     * @return: Boolean
     * @Author: zhangrm
     * @Date: 2020/05/27 0027
     */
    @SysLog("删除省市区信息")
    @ApiOperation(value = "删除省市区信息", notes = "pc:positioninfo:delete")
    @ApiImplicitParam(value = "省市区信息Id", name = "id", dataType = "Long", required = true)
    @DeleteMapping("/delete/{id}")
    @PreAuthorize("@pms.hasPermission('pc:positioninfo:delete')")
    public R<Boolean> delete(@PathVariable("id") Long id) {
        return R.ok(iDogComPositioninfoService.deleteObj(id));
    }


    /**
     * @Description: 修改省市区信息
     * @Param: PositioninfoEditDto
     * @return: Boolean
     * @Author: zhangrm
     * @Date: 2020/05/27 0027
     */
    @SysLog("修改省市区信息")
    @ApiOperation(value = "修改省市区信息", notes = "pc:positioninfo:edit")
    @PutMapping("/edit")
    @PreAuthorize("@pms.hasPermission('pc:positioninfo:edit')")
    public R<Boolean> edit(@Valid @RequestBody PositioninfoEditDto obj) {
        return R.ok(iDogComPositioninfoService.editObj(obj));
    }

    /**
     * @Description: 设置省市区信息是否可用
     * @Param: PositioninfoEditDto
     * @return: Boolean
     * @Author: zhangrm
     * @Date: 2020/05/27 0027
     */
    @SysLog("设置省市区信息是否可用")
    @ApiOperation(value = "设置省市区信息是否可用", notes = "pc:positioninfo:edit")
    @PutMapping("/editUse/{id}")
    @PreAuthorize("@pms.hasPermission('pc:positioninfo:edit')")
    public R<Boolean> editUse(@PathVariable("id") Long id) {

        return R.ok(iDogComPositioninfoService.editObjUse(id));
    }


    /**
     * @Description: 分页省市区信息列表
     * @Param: PositioninfoFormDto
     * @return: IPage<PcPositioninfoVo>
     * @Author: zhangmr
     * @Date: 2020/05/27 0027
     */
    @ApiOperation(value = "分页省市区信息列表", notes = "pc:positioninfo:page")
    @GetMapping("/page")
    @PreAuthorize("@pms.hasPermission('pc:positioninfo:page')")
    public R<IPage<PositioninfoVo>> page(PageParam page, PositioninfoFormDto obj) {
        IPage<PositioninfoVo> list = iDogComPositioninfoService.getPageList(page, obj);
        return R.ok(list);
    }

    /**
     * @Description: 全国省市区信息
     * @Param:
     * @return:
     * @Author: zhangmr
     * @Date:
     */
    @ApiOperation(value = "全国省市区信息", notes = "全国省市区信息")
    @GetMapping("/allPositioninfo")
    public R<AllPositioninfoVo> page() {
        return R.ok(iDogComPositioninfoService.getAllPositioninfo());
    }


    /**
     * @Description: 通过父ID获取子省市区信息
     * @Param:
     * @return:
     * @Author: zhangmr
     * @Date:
     */
    @ApiOperation(value = "通过父ID获取子省市区信息", notes = "通过父ID获取子省市区信息")
    @ApiImplicitParam(name = "id", value = "省市区标识", required = true, dataType = "Long", paramType = "query")
    @GetMapping("/positioninfo/{id}")
    public R<List<com.dog.basics.bean.vo.api.common.PositioninfoVo>> getPositioninfo(@PathVariable("id") Long id) {
        return R.ok(iDogComPositioninfoService.getPositioninfo(id));
    }

}
